<template>
  <div class="header-query-li">
    <div class="query-label" :style="borderStyle">{{ query.label + "：" }}</div>
    <div class="label-li" :style="borderStyle" @click="callBack">
      <!-- <span 去除style为了解决主题更换之后样式还是默认的情况
        :class="active === null ? 'active' : ''"
        :style="active === null ? titleFont : mrzts"
        >全部</span
      > -->
      <span :class="active === null ? 'active' : ''">全部</span>
    </div>
    <div
      v-for="(item, index) in dataList"
      :key="'label-' + index"
      class="label-li"
      @click="callBack(item)"
    >
      <!-- <span
        :class="active === item.value ? 'active' : ''"
        :style="active === item.value ? titleFont : mrzts"
        >{{ item.name }}</span
      > -->
      <span :class="active === item.value ? 'active' : ''">{{
        item.name
      }}</span>
    </div>
  </div>
</template>

<script>
import { queryAllServiceParamsLabel } from '@/api/portal/manager/setting/index';
export default {
  name: 'OfficeHallItem', // 办事大厅分类模块：主管部门、办事方式、服务对象部分
  props: {
    params: {
      type: Object,
      default() {
        return {};
      }
    },
    layout: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      query: {},
      dataList: [],
      active: null,
      customStyle: {},
      titleStyle: {},
      bodyStyle: {},
      borderStyle: {},
      titleFont: {},
      mrzts: {}
    };
  },
  computed: {
    themes() {
      return this.$store.getters.theme;
    }
  },
  watch: {
    layout: {
      handler(newData, oldData) {
        this.customStyle = newData;
        this.titleStyle = {
          backgroundColor: newData.mrlb,
          opacity: newData.tmd
        };
        this.titleFont = { color: newData.lmys };
        this.mrzts = { color: newData.fontColor };
        this.activeStyle = {
          color: newData.xsys,
          backgroundColor: newData.xzbjs
        };
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    params: {
      handler(newData, oldData) {
        this.active = null;
        this.query = newData;
        this.initData({ code: newData.column });
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    themes: {
      handler(val, oldVal) {
        this.$nextTick(() => {
          this.borderStyle.borderRadius = val.bkdx;
          // if (this.temp.sfxsbk === true) {
          //   this.borderStyle.border = "1px solid " + val.bkys;
          // }
          // if (this.temp.bkyy === true) {
          //   this.borderStyle.boxShadow = "0 2px 4px rgba(0, 0, 0, .12)";
          // }
          this.borderStyle.background = val.columnGroundColor;
          this.borderStyle.color = val.fontColor;
          this.borderStyle = Object.assign({}, this.borderStyle);
        });
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    initData(data) {
      queryAllServiceParamsLabel(data)
        .then(res => {
          const { data } = res;
          console.log(res);
          this.dataList = data;
        })
        .catch(() => {
          this.dataList = [];
        });
    },
    callBack(data) {
      if (
        undefined !== data &&
        undefined !== data.value &&
        data.value !== null
      ) {
        this.active = data.value;
        this.$emit('call-back', { code: this.query.column, value: data.value });
      } else {
        this.active = null;
        this.$emit('call-back', { code: this.query.column, value: null });
      }
    }
  }
};
</script>

<style scoped>
.header-query-li {
  min-height: 50px;
  border-bottom: 1px dashed #efefef;
  display: flex;
  flex-flow: row wrap;
}
.query-label {
  flex: 0 1 auto;
  width: 100px;
  text-align: center;
  line-height: 50px;
  font-weight: bolder;
}
.label-li {
  flex: 0 1 auto;
  line-height: 50px;
}
.label-li span {
  border-radius: 3px;
  cursor: pointer;
  padding: 5px 10px;
  box-sizing: border-box;
}
.active,
.label-li span:hover {
  background-color: #409eff;
}
</style>
